package com.file.system.plugin.jackson;

import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class JacksonConf {
    @Bean
    // 创建一个Jackson2ObjectMapperBuilderCustomizer对象，用于自定义Jackson2ObjectMapperBuilder
    public Jackson2ObjectMapperBuilderCustomizer jackson2ObjectMapperBuilderCustomizer() {
        Jackson2ObjectMapperBuilderCustomizer customizer = jacksonObjectMapperBuilder ->
                // 为Long类型设置ToStringSerializer序列化器
                jacksonObjectMapperBuilder
                        .serializerByType(Long.class, ToStringSerializer.instance)
                        // 为long类型设置ToStringSerializer序列化器
                        .serializerByType(long.class, ToStringSerializer.instance)
                        // 为Long.TYPE类型设置ToStringSerializer序列化器
                        .serializerByType(Long.TYPE, ToStringSerializer.instance);
        return customizer;
    }
}
